package mspbots.data.tl.prod.quickbooks.listener;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import mspbots.data.tl.entity.ResultEntity;
import mspbots.data.tl.prod.quickbooks.service.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Log4j2
@Service
@Component
@RequiredArgsConstructor
public class QuickbooksSyncListenner {

    private final QuickbooksAccountService quickbooksAccountService;
    private final OnlineAccountService onlineAccountService;
    private final OnlineInvoiceService onlineInvoiceService;
    private final OnlineProfitAndLossStandardService onlineProfitAndLossStandardService;
    private final OnlineBalanceSheetService onlineBalanceSheetService;
    private final QuickBooksDesktopCustomersService quickBooksDesktopCustomersService;
    private final OnlineGeneralLedgerService onlineGeneralLedgerService;

    @RabbitListener(queues = "quick-books-desktop.account.tl")
    public void syncQuickbookAccount(JsonNode node) {
        quickbooksAccountService.sync(node);
    }

    @RabbitListener(queues = "quick-books-online.account.tl")
    public void syncOnlineAccount(ResultEntity entity) {
        onlineAccountService.sync(entity);
    }

    @RabbitListener(queues = "quick-books-desktop.customers.tl")
    public void syncQuickBooksDesktopCustomers(JsonNode node) {
        quickBooksDesktopCustomersService.sync(node);
    }

    @RabbitListener(queues = "quick-books-online.invoice.tl")
    public void syncOnlineInvoice(ResultEntity entity) {
        onlineInvoiceService.sync(entity);
    }

//    @RabbitListener(queues = "quick-books-online.ProfitAndLoss.standard.tl")
    public void syncOnlineProfitAndLossStandard(ResultEntity entity) {
        onlineProfitAndLossStandardService.sync(entity);
    }

    @RabbitListener(queues = "quick-books-online.balance.sheet.tl")
    public void syncOnlineBalanceSheet(ResultEntity entity) {
        onlineBalanceSheetService.sync(entity);
    }

    @RabbitListener(queues = "quick-books-online.general.ledger.tl")
    public void syncOnlineGeneralLedger(ResultEntity entity) {
        onlineGeneralLedgerService.sync(entity);
    }

}
